package com.smart.home.command;

import com.smart.home.command.common.BaseCommand;
import com.smart.home.command.common.CommonCode;
import com.smart.home.netty.NettyUtils;
import com.smart.home.netty.handler.AbstractChannelInboundHandler;
import com.smart.home.netty.handler.IndoorEnvironmentCommandHandler;

import java.util.Map;

/**
 * 环境控制
 *
 * @author zhangpeng
 * @version 1.0
 * @date 2017-03-10
 */
public class EnvironmentCommand extends BaseCommand {

    /**
     * 温度
     */
    public static final String TEMPERATURE = "temperature";
    /**
     * 湿度
     */
    public static final String HUMIDITY = "humidity";
    /**
     * 设防
     */
    public static final String DEFENSE = "defense";

    public EnvironmentCommand(String deviceCode, String host, int port) {
        super(deviceCode, host, port);
    }

    /**
     * 温湿度设防撤防信息获取
     *
     * @return
     */
    public Map<String, Object> queryEnvironment() {
        String command = getDeviceCode() + CommonCode.TEMPERATURE_HUMIDITY_DEFENSE;
        IndoorEnvironmentCommandHandler handler = new IndoorEnvironmentCommandHandler(command);
        AbstractChannelInboundHandler result = NettyUtils.sendCommand(handler, getHost(), getPort());
        return (Map<String, Object>) result.getObj();
    }

}
